#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi

#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > dpt_hbr_finp.info <<%EOF%
   dpt_hbr_finp
   ------------
   Molecule:       HBr in C2v
   Wave Function:  CCSD, CCSD(T) / AhlrichsVDZ (frozen core)
   Test Purpose:   Finite-field (+0.005) first-order DPT correction
%EOF%

#######################################################################
#  INTEGRAL INPUT
#######################################################################
cat > dpt_hbr_finp.mol <<%EOF%
BASIS
Ahlrichs-VDZ      
First-order relativistic corrections (frozen core)

    2    2  X  Y      1.00D-15
       35.0   1
Br      0.00000000000000    0.00000000000000    0.00000000000000       *
        1.0   1
H       0.00000000000000    0.00000000000000    2.67207254785060       *
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > dpt_hbr_finp.dal <<%EOF%
**DALTON INPUT
.RUN WAVE FUNCTIONS
**INTEGRAL
.FINDPT
 0.005
**WAVE FUNCTION
.CC
*SCF INP
.THRESH
 1.0D-10
*CC INP
.CCSD
.CC(T)
.PRINT
 4
.THRENR
1.0D-10
.FROIMP
 5 2 2 0
 0 0 0 0
**END OF DALTON INPUT
%EOF%

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL > dpt_hbr_finp.check
cat >> dpt_hbr_finp.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

#             Total CCSD  energy:                 -2572.9818039497
#             Total energy CCSD(T):               -2572.9839663780

CRIT1=`$GREP "Total CCSD  energy:                 \-2572\.9818039[45]" $log | wc -l`
TEST[1]=`expr   $CRIT1`
CTRL[1]=4
ERROR[1]="CCSD energy with finite DPT correction not correct"

CRIT2=`$GREP "\-2572\.9839663" $log | wc -l`
TEST[2]=`expr   $CRIT2`
CTRL[2]=3
ERROR[2]="CCSD(T) energy with finite DPT correction not correct"

PASSED=1
for i in 1 2
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi
%EOF%

chmod +x dpt_hbr_finp.check
#######################################################################
